package com.orange.score.activity.entry;

import android.content.Context;
import android.content.res.Resources;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import com.orange.score.model.match.Match;
import java.util.List;

public class RealtimeMatchListAdapter extends PageableAdapter<Match>
{
  static int CARD_WIDTH;
  static int MAX_TEAM_NAME_WIDTH = 100;
  private static final String TAG;
  FollowMatchCallBack followMatchCallBack;

  static
  {
    CARD_WIDTH = 20;
    TAG = RealtimeMatchListAdapter.class.getName();
  }

  public RealtimeMatchListAdapter(List<Match> paramList, Context paramContext, FollowMatchCallBack paramFollowMatchCallBack)
  {
    super(paramList, paramContext);
    this.followMatchCallBack = paramFollowMatchCallBack;
    DisplayMetrics localDisplayMetrics = paramContext.getResources().getDisplayMetrics();
    float f = localDisplayMetrics.widthPixels / localDisplayMetrics.xdpi / 160.0F;
    Log.d(TAG, "window metrics = " + localDisplayMetrics.toString() + ", width dip is " + f);
    if (f < 300.0F)
    {
      MAX_TEAM_NAME_WIDTH = 50;
      CARD_WIDTH = 10;
      Log.d(TAG, "MAX_TEAM_NAME_WIDTH = " + MAX_TEAM_NAME_WIDTH + ", CARD_WIDTH=" + CARD_WIDTH);
    }
  }

  private boolean hasCard(String paramString)
  {
    int i;
    if ((paramString != null) && (paramString.length() > 0) && (Integer.parseInt(paramString) > 0))
      i = 1;
    while (true)
    {
      return i;
      i = 0;
    }
  }

  private void setCardData(String paramString, View paramView, TextView paramTextView)
  {
    if (hasCard(paramString))
    {
      paramTextView.setText(paramString);
      paramTextView.setVisibility(0);
    }
    while (true)
    {
      return;
      paramTextView.setVisibility(8);
    }
  }

  public View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
  {
    Holder localHolder;
    View localView;
    String str;
    SpannableStringBuilder localSpannableStringBuilder;
    if (paramView != null)
      localHolder = (Holder)paramView.getTag();
    while (paramInt + this.startIndex >= this.list.size())
    {
      localView = null;
      return localView;
      localHolder = new Holder(this);
      paramView = LayoutInflater.from(this.context).inflate(2130903091, null);
      localHolder.homeTeamName = ((TextView)paramView.findViewById(2131558588));
      localHolder.awayTeamName = ((TextView)paramView.findViewById(2131558591));
      localHolder.homeTeamRed = ((TextView)paramView.findViewById(2131558587));
      localHolder.awayTeamRed = ((TextView)paramView.findViewById(2131558593));
      localHolder.homeTeamYellow = ((TextView)paramView.findViewById(2131558586));
      localHolder.awayTeamYellow = ((TextView)paramView.findViewById(2131558594));
      localHolder.leagueName = ((TextView)paramView.findViewById(2131558583));
      localHolder.chupan = ((TextView)paramView.findViewById(2131558592));
      localHolder.matchStatus = ((TextView)paramView.findViewById(2131558585));
      localHolder.matchStatusOnly = ((TextView)paramView.findViewById(2131558589));
      localHolder.matchStartTime = ((TextView)paramView.findViewById(2131558584));
      localHolder.matchScore = ((TextView)paramView.findViewById(2131558590));
      localHolder.firstHalfScore = ((TextView)paramView.findViewById(2131558595));
      localHolder.followButton = ((Button)paramView.findViewById(2131558582));
      paramView.setTag(localHolder);
    }
    Match localMatch = (Match)this.list.get(paramInt + this.startIndex);
    localHolder.followButton.setOnClickListener(new View.OnClickListener(this, localMatch, localHolder)
    {
      public void onClick()
      {
        boolean bool;
        this.this$0.followMatchCallBack.followUnfollowMatch(this.val$match);
        Button localButton = this.val$holder.followButton;
        if (this.val$holder.followButton.isSelected())
          bool = false;
        while (true)
        {
          localButton.setSelected(bool);
          return;
          bool = true;
        }
      }
    });
    if (localMatch.isFollow())
    {
      localHolder.followButton.setSelected(true);
      localHolder.homeTeamName.setText(localMatch.getHomeTeamName());
      localHolder.awayTeamName.setText(localMatch.getAwayTeamName());
      localHolder.leagueName.setText(localMatch.getLeagueName());
      localHolder.leagueName.setTextColor(localMatch.getLeagueColor());
      localHolder.matchStartTime.setText(localMatch.getDateString());
      localHolder.homeTeamRed.setText(localMatch.getHomeTeamRed());
      localHolder.homeTeamYellow.setText(localMatch.getHomeTeamYellow());
      localHolder.awayTeamRed.setText(localMatch.getAwayTeamRed());
      setCardData(localMatch.getHomeTeamYellow(), paramView, localHolder.homeTeamYellow);
      setCardData(localMatch.getHomeTeamRed(), paramView, localHolder.homeTeamRed);
      setCardData(localMatch.getAwayTeamRed(), paramView, localHolder.awayTeamRed);
      setCardData(localMatch.getAwayTeamYellow(), paramView, localHolder.awayTeamYellow);
      int i = MAX_TEAM_NAME_WIDTH;
      if (!(hasCard(localMatch.getHomeTeamYellow())))
        i += CARD_WIDTH;
      if (!(hasCard(localMatch.getHomeTeamRed())))
        i += CARD_WIDTH;
      localHolder.homeTeamName.setMaxWidth(i);
      int j = MAX_TEAM_NAME_WIDTH;
      if (!(hasCard(localMatch.getAwayTeamYellow())))
        j += CARD_WIDTH;
      if (!(hasCard(localMatch.getAwayTeamRed())))
        j += CARD_WIDTH;
      localHolder.awayTeamName.setMaxWidth(j);
      if (!(localMatch.needDisplayScore()))
        break label999;
      str = localMatch.getMatchStatusOrMinutString();
      if (!(str.contains("'")))
        break label973;
      localSpannableStringBuilder = new SpannableStringBuilder();
      localSpannableStringBuilder.append(str);
      localSpannableStringBuilder.setSpan(new ForegroundColorSpan(localMatch.getMatchStatusColor()), 0, str.length() - 1, 18);
      if (System.currentTimeMillis() / 1000L % 2L != 0L)
        break label941;
      localSpannableStringBuilder.setSpan(new ForegroundColorSpan(-65536), str.length() - 1, str.length(), 18);
      localHolder.matchStatus.setText(localSpannableStringBuilder);
      localHolder.matchStatus.setVisibility(0);
      localHolder.matchScore.setText(localMatch.getHomeTeamScore() + ":" + localMatch.getAwayTeamScore());
      localHolder.matchScore.setVisibility(0);
      localHolder.matchScore.setTextColor(localMatch.getMatchScoreColor());
      localHolder.matchStatusOnly.setVisibility(4);
      localHolder.firstHalfScore.setText("(" + localMatch.getHomeTeamFirstHalfScore() + ":" + localMatch.getAwayTeamFirstHalfScore() + ")");
      if (!(localMatch.hasFirstHalfScore()))
        break label1055;
      localHolder.firstHalfScore.setVisibility(0);
      if (!(localMatch.hasChupan()))
        break label1067;
      localHolder.chupan.setVisibility(0);
      localHolder.chupan.setText(localMatch.getCrownChupanString());
      if (!(localMatch.isScoreJustUpdate()))
        break label1079;
      Log.d(TAG, "score is just updated, set special background");
      paramView.setBackgroundResource(2130837637);
    }
    while (true)
    {
      while (true)
      {
        while (true)
        {
          while (true)
          {
            while (true)
            {
              while (true)
              {
                while (true)
                {
                  while (true)
                    localView = paramView;
                  localHolder.followButton.setSelected(false);
                }
                label941: localSpannableStringBuilder.setSpan(new ForegroundColorSpan(-3355444), str.length() - 1, str.length(), 18);
              }
              label973: localHolder.matchStatus.setText(str);
              localHolder.matchStatus.setTextColor(localMatch.getMatchStatusColor());
            }
            label999: localHolder.matchStatusOnly.setText(localMatch.getMatchStatusString());
            localHolder.matchStatusOnly.setVisibility(0);
            localHolder.matchStatusOnly.setTextColor(localMatch.getMatchStatusColor());
            localHolder.matchStatus.setVisibility(4);
            localHolder.matchScore.setVisibility(4);
          }
          label1055: localHolder.firstHalfScore.setVisibility(4);
        }
        label1067: localHolder.chupan.setVisibility(4);
      }
      label1079: paramView.setBackgroundResource(2130837700);
    }
  }

  class Holder
  {
    TextView awayTeamName;
    TextView awayTeamRed;
    TextView awayTeamYellow;
    TextView chupan;
    TextView firstHalfScore;
    Button followButton;
    TextView homeTeamName;
    TextView homeTeamRed;
    TextView homeTeamYellow;
    TextView leagueName;
    TextView matchScore;
    TextView matchStartTime;
    TextView matchStatus;
    TextView matchStatusOnly;
  }
}